DATAS SEGMENT
  i DW ?
  sum DW ?
  n DW ?
DATAS ENDS

CODES SEGMENT

main   proc   far
  ASSUME CS:CODES,DS:DATAS
START:
  MOV AX,DATAS
  MOV DS,AX
  MOV sum,1
  call get
  mov n,DI
  MOV BX,n
  MOV i,BX
  MOV n,BX
  MOV BX,n
  CMP BX,1
  JGE rotate8
  mov cx,n
  call put
  JMP rotate16
rotate8:
  MOV BX,i

  CMP BX,0
  JLE rotate15
  MOV AX,sum
  MUL i
  MOV BX,AX
  MOV sum,BX
  MOV BX,i
  SUB BX,1
  MOV i,BX
  JMP rotate8
rotate15:
  mov cx,sum
  call put
rotate16:
  MOV AH,4CH
  INT 21H
main   endp



get  proc  near
  mov DI,0
  MOV AH,1
  INT 21H
  cmp al,'-'
  jz   getFirstChar
  sub al,30H
  CBW
  add DI,ax
  jmp loop1
getFirstChar:
  MOV AH,1
  INT 21H
  sub al,30H
  not al
  inc al
  cbw
  add DI,ax
  jmp loop2
loop1:
  MOV AH,1
  INT 21H
  cmp al,0DH
  jz next1
  sub al,30H
  MOV bh,al
  mov ax,DI
  mov bl,10
  imul bl
  add al,bh
  mov DI,ax
  jmp loop1
loop2:
  MOV AH,1
  INT 21H
  cmp al,0DH
  jz next1
  sub al,30H
  MOV bh,al
  not bh
  inc bh
  mov ax,DI
  mov bl,10
  imul bl
  add al,bh
  mov DI,ax
  jmp loop2
next1:
  ret
get    endp


put  proc  near
  mov dl,0AH
  mov ah,2
  int 21h
  TEST cx,8000H
  je pos
  mov dl,'-'
  mov ah,2
  int 21h
  mov ax,cx
  not AX
  INC AX
  MOV BX,10
  MOV CX,0 
  jmp pr1
pos: 
  mov ax,cx
  MOV BX,10
  MOV CX,0 
pr1:  
  CMP AX,10
  JB ok
  XOR DX,DX
  DIV BX
  ADD DL,30H
  PUSH DX
  XOR DX,DX
  INC CX
  JMP pr1
ok:
  ADD AL,30H
  PUSH AX
  INC CX
pr2:
  POP DX
  MOV AH,2
  INT 21H
  LOOP pr2
  ret
put  endp

CODES ENDS

END START